package benny_driving_ser.servlet.listener;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SessionListener implements HttpSessionListener {
	public static Set<HttpSession> SESSIONS = new HashSet<HttpSession>();

	public void sessionCreated(HttpSessionEvent arg0) {
		synchronized (SessionListener.SESSIONS) {
			SESSIONS.add(arg0.getSession());
		}
		System.out.println("session create");
	}

	public void sessionDestroyed(HttpSessionEvent arg0) {
		if (SESSIONS.contains(arg0.getSession())) {
			synchronized (SessionListener.SESSIONS) {
				SESSIONS.remove(arg0.getSession());
			}
		}
		System.out.println("session destroy");
	}

}
